package com.example.demo.repository;

import com.example.demo.entity.Outpatient;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OutpatientRepository extends JpaRepository <Outpatient,Integer>{
    @Query(value = "select t._live,t.outpatientid,t.outpatientname from Outpatient t where t._live=1  order by t.outpatientid desc limit :page,:pageSize",nativeQuery = true)
    List<Outpatient> findAllByAny(@Param("page")Integer page,@Param("pageSize")Integer pageSize);

    @Query("select t from Outpatient t where t._live=1 and t.outpatientname=:outpatientname")
    Outpatient findAllByName(@Param("outpatientname")String outpatientname);

    @Query("select t from Outpatient t where t._live=1 and t.outpatientid=:id")
    Outpatient findAllBy_live(@Param("id")Integer id);

//    @Query("update Outpatient set _live=")
//    Integer updateOutpatientById(@Param("outpatientid")Integer outpatientid);

    @Query(value = "SELECT COUNT(*) FROM Outpatient t WHERE t._live=1",nativeQuery = true)
    int total();
}
